#/usr/bin/Rscript
library("ggplot2")

on_100_20 <- read.table("on/profits.dat")$V1
op_100_20 <- read.table("rf/profits.dat")$V1
ut_100_20 <- read.table("ut/profits.dat")$V1

#Ganhos para risco de 1_5_10%

gop_100_20 <- (op_100_20 - on_100_20) / abs(on_100_20)
gut_100_20 <- (ut_100_20 - on_100_20) / abs(on_100_20)

#100 usuários
jpeg("ganhos_100.jpg")


heuristica <- c("RF", "UT")
risco <- c(1, 1)
ganho <- c(mean(gop_100_20), mean(gut_100_20))
interval <- c( 1.96*sd(gop_100_20)/sqrt(length(gop_100_20)), 1.966*sd(gut_100_20)/sqrt(length(gut_100_20)) )

pd <- position_dodge(.1) # move them .05 to the left and right
dados <- data.frame(heur=heuristica, ris=risco, gan=ganho, ci=interval)

limits <- aes(x=ris, y=100 * gan, ymin=100 * (gan-ci), ymax=100 * (gan+ci), colour=heur, fill=heur, shape=heur)
ggplot(dados, limits) + 
    geom_point(position=pd, size=3) + xlab("Risco de negação de serviço") + ylab("Ganho") + opts(title="Ganho de heurísticas em relação a heurística ON") + theme_bw() + scale_y_continuous(breaks=c(-60, -50, -40, -30, -20, -10, 0, 1, 2, 4, 5)) + scale_x_continuous(breaks=c(0, 5, 10, 15, 20)) + scale_shape_manual(values=c(19, 3, 0)) + geom_errorbar(limits)
 
dev.off()

